package com.jiangjiang.eshop.commodity.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.commodity.convert.GoodsSkuSalePropertyValueConvert;
import com.jiangjiang.eshop.commodity.dao.GoodsSkuSalePropertyValueMapper;
import com.jiangjiang.eshop.commodity.domain.GoodsSkuSalePropertyValueEntity;
import com.jiangjiang.eshop.commodity.dto.GoodsSkuSalePropertyValueDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jws.Oneway;
import java.util.List;

/**
 * @ClassName GoodsSkuSalePropertyValueService
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/2 18:08
 * @Version 1.0
 **/
@Service
public class GoodsSkuSalePropertyValueService
        extends ServiceImpl<GoodsSkuSalePropertyValueMapper, GoodsSkuSalePropertyValueEntity> {

    @Autowired
    private GoodsSkuSalePropertyValueConvert goodsSkuSalePropertyValueConvert;
    /**
     * 根据skuId 批量删除
     * @param skuIds sku id集合
     */
    public void batchRemoveBySkuIds(List<Long> skuIds) {
        LambdaQueryWrapper<GoodsSkuSalePropertyValueEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.in(GoodsSkuSalePropertyValueEntity::getGoodsSkuId, skuIds);
        this.remove(wrapper);
    }

    /**
     * 根据sku id 查询商品的可销售属性数据
     * @param goodsSkuId 商品sku id
     * @return 查询结果
     */
    public List<GoodsSkuSalePropertyValueDTO> queryByGoodsSkuId(Long goodsSkuId){
        LambdaQueryWrapper<GoodsSkuSalePropertyValueEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(GoodsSkuSalePropertyValueEntity::getGoodsSkuId, goodsSkuId);
        return goodsSkuSalePropertyValueConvert.convertEntities2DTOList(this.list(wrapper));
    }
}
